<template>
	<view class="">
		<riding-risk-component onAdLoad="onAdLoad" onSuccess="onSuccess" onClose="onClose" onAdError="onAdError"
			:result="result"></riding-risk-component>
		<u-popup v-model="show" mode="center">
			<view class="" style="width: 100%;text-align: center;">
				<!-- 	<image class="" mode="widthFix" src="/static/success.png" v-if="flag==1" class="img"></image> -->
				<image mode="widthFix" src="/static/err1.png" @click="getjump" class="img"></image>
				<image src="../../static/queren.png" mode="widthFix" class="img" style="margin-top: 20rpx;"
					@click="getjump"></image>
			</view>
		</u-popup>

		<view class="" style="background-color: #e1f3ff;height: 100vh;" v-if="flag">
			<image src="https://web.78keji.cn/images/yundian/背景@3x.png" mode="widthFix" style="width: 100%;"></image>
			<view class="" style="padding: 24rpx;">
				<view class="bns">
					<image src="https://web.78keji.cn/images/yundian/biaoti1.png" mode="widthFix" style="width: 100%;">
					</image>
					<image src="https://web.78keji.cn/images/yundian/1.gif" mode="widthFix"
						style="width: 100%;margin-top: 20rpx;"></image>
					<image src="https://web.78keji.cn/images/yundian/btn2@3x.png" mode="widthFix"
						style="width: 100%;margin-top:30rpx;" @click="kabao"></image>

				</view>
				<view class="bns" style="margin-top: 40rpx;">
					<image src="https://web.78keji.cn/images/yundian/biaoti2.png" mode="widthFix" style="width: 100%;">
					</image>
					<image src="https://web.78keji.cn/images/yundian/2.gif" mode="widthFix"
						style="width: 100%;margin-top: 20rpx;"></image>
					<image src="https://web.78keji.cn/images/yundian/btn.png" mode="widthFix"
						style="width: 100%;margin-top:30rpx;" @click="chongzhi"></image>

				</view>
				<view class="" style="height: 100rpx;">

				</view>
			</view>
		</view>


	</view>
</template>

<script>
	import zfbUrlUtil from "../../utils/zfbUrlUtil";
	import {
		alternateProductInfo
	} from '../../api/index1.js'
	import {
		event
	} from '../../api/index2.js'

	export default {
		data() {
			return {
				flag: false,
				show: false,
				
				shows: '1',
                trace:"",
				a:'',
				orderNo:"",
				param:""

			}
		},
		onLoad(option) {
			uni.hideHomeButton()
			// my.alert({
			// 	content:JSON.stringify(option)
			// })
			this.a = option.a
			this.trace = option.trace
			this.shows = option.shows
			this.param = option.param
			this.orderNo = option.orderNo
			event({
				t: option.trace,
				e: 2,
				f: ''
			}).then((res) => {

			})


			this.$scope.onAdLoad = this.onAdLoad.bind(this)
			this.$scope.onSuccess = this.onSuccess.bind(this)
			this.$scope.onClose = this.onClose.bind(this)
			this.$scope.onAdError = this.onAdError.bind(this)

		},
		methods: {
			getjump() {
				//兜底


				if (this.shows == '1') {
					alternateProductInfo({
						traceId: this.trace,
						channelCode: this.a
					}).then((res) => {

						let link = res.data.productLink + '&schemeCode=' + res.data.schemeCode
						let url = zfbUrlUtil.wrapUrl(link)
						this.jump(url)
					})
				} else {
					uni.showToast({
						title: '暂无更多活动',
						icon: 'none', //将值设置为 success 或者 ''
						duration: 2000 //持续时间为 2秒
					})
				}

			},
			jump(url) {
				my.ap.openURL({
					url: url,
					success: (res) => {
						console.log('openURL success', res)
					},
					fail: (err) => {
						console.log('openURL success', err)
					}
				});
			},
			chongzhi() {

				let url = 'https://ulink.alipay.com/?scheme=' + encodeURIComponent(
					'alipayqr://platformapi/startapp?saId=10000003')
				this.jump(url)
			},
			kabao() {



				let url = 'https://ulink.alipay.com/?scheme=' + encodeURIComponent(
					'alipays://platformapi/startapp?appId=20000227')
				this.jump(url)


			},
			onAdLoad(interstitialAd, spaceCode) {
				interstitialAd.show({
					spaceCode,
					rtaExtMap: {
						param: this.param,
						orderNo: this.orderNo,
						channelCode: this.a,
						organization_type: 'hospital',
						organization_sub_type: 'general_hospital',
						device_location: 'outpatient_department',
						device_id: '111111',
						public_opinion_level: 'low_risk',
						touch_point_location: 'index',
						touch_point_type: 'full_screen',
					},
				});
			},
			onSuccess() {
				console.log("加载成功")

				event({
					t: this.trace,
					e: 13,
					f: ''
				}).then((res) => {

				})
			},
			onClose() {

				if (uni.getStorageSync('flag')) {
					if (uni.getStorageSync('flag') == false) {
						this.show = true
					} else {
						this.flag = true
					}
				} else {
					if (this.flag == false) {
						this.show = true


					} else {
						this.show = false
						this.flag = true

					}
				}
				event({
					t: this.trace,
					e: 17,
					f: ''
				}).then((res) => {

				})

			},
			onAdError(err) {
				console.log(err, "加载失败")

				this.show = true
				console.log(this.show, this.flag)
				event({
					t: this.trace,
					e: 14,
					f: ''
				}).then((res) => {

				})
			},
			result(e) {
				console.log("办理结果", e)

				if (e == '1603') {

					this.show = false
					this.flag = true
					uni.setStorageSync('flag', true)
					console.log(this.show, this.flag, '结果')
					event({
						t: this.trace,
						e: 15,
						f: ''
					}).then((res) => {
					
					})
				} else {

					this.flag = false
					this.show = true
					uni.setStorageSync('flag', false)
					console.log(this.show, this.flag, '结果1')
					event({
						t: this.trace,
						e: 15,
						f: ''
					}).then((res) => {
					
					})
				}
			}
		}
	}
</script>